//
//  QZServiceItemsVc.m
//  WeiWeiHaircut
//
//  Created by 上官惠阳 on 15/12/16.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZServiceItemsVc.h"
#import "QZServiceItemsCell.h"

@interface QZServiceItemsVc ()

@end

@implementation QZServiceItemsVc
{
    NSMutableArray *_seleteItemArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _seleteItemArr = [[NSMutableArray alloc]init];
    
    [self titleWithSting:@"服务项目"];
    
    [self addBtnOnNavWithTitle:@"预约" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    
    [self addBtnOnNavWithTitle:@"确定" andImageName:nil andTarget:self andAction:@selector(sureService) andFrame:CGRectMake(0, 0, 40, 20) andDirection:right];
    
    [self createTableViewWithPlainStyle:NO andSeparatorStyleNone:NO andBackGroudImageName:nil];
    [self registCellWithNib:@"QZServiceItemsCell" addIdentifier:@"itemCell" addHeight:40];
    
    [self requestData];
}
-(void)requestData
{
    [self requestWithKeys:nil andValues:nil andUrlKey:@"HairOrder.GetAppointCateAll" isCache:YES];
}
-(void)request_POST_FinishValue:(id)value tagNSString:(NSString *)tag
{
    NSLog(@"value = %@",value);
    if ([value[@"data"][@"status"] intValue] == 100) {
        [self.tableSource addObject:value[@"data"][@"data"][@"list"]];
        if (_lastSeleteItemArr) {
            [_seleteItemArr setArray:_lastSeleteItemArr];
        }
        [self.tableView reloadData];
    }
}
//确定
-(void)sureService
{
    if (self.seletedBlock) {
        self.seletedBlock(_seleteItemArr);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)loadCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.tableSource[indexPath.section][indexPath.row];
    QZServiceItemsCell *itemCell = (QZServiceItemsCell *)cell;
    itemCell.textLabel.text = dic[@"name"];
    if ([_seleteItemArr containsObject:dic]) {
        itemCell.seleteBtn.selected = YES;
    }else{
        itemCell.seleteBtn.selected = NO;
    }
}
-(void)actionAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.tableSource[indexPath.section][indexPath.row];
    QZServiceItemsCell *itemCell = [self.tableView cellForRowAtIndexPath:indexPath];
    if (itemCell.seleteBtn.selected) {
        [_seleteItemArr removeObject:dic];
    }else{
       [_seleteItemArr addObject:dic];
    }
    
    [self.tableView reloadData];
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
